7a610b9e2624375d6765793787a9ba072e0bb706,extensions/modules/src/org/exist/xquery/modules/sql/SQLModule.java,SQLModule,closeAllConnections,#XQueryContext#,165

Before Change


     */
    private static void closeAllConnections(XQueryContext xqueryContext) {
        // get the existing Connections map from the context
        Map<Long, Connection> connections = ModuleUtils.retrieveContextMap(xqueryContext, SQLModule.CONNECTIONS_CONTEXTVAR);

        if(connections != null) {

            // iterate over each Connection
            for(Entry<Long, Connection> entry : connections.entrySet()) {
                Long conID = entry.getKey();
                Connection con = entry.getValue();

                try {

                    // close the Connection
                    con.close();
                } catch(SQLException se) {
                    LOG.debug("Unable to close JDBC Connection", se);
                }
            }

            //empty the map
            connections.clear();

            // update the context
            ModuleUtils.storeContextMap(xqueryContext, SQLModule.CONNECTIONS_CONTEXTVAR, connections);
        }
    }

After Change


     * @param  xqueryContext  The context to close JDBC Connections for
     */
    private static void closeAllConnections(XQueryContext xqueryContext) {
        ModuleUtils.modifyContextMap(xqueryContext, SQLModule.CONNECTIONS_CONTEXTVAR, new ContextMapEntryModifier<Connection>(){
            
            @Override 
            public void modify(Map<Long, Connection> map) {
                super.modify(map);
                
                //empty the map
                map.clear();
            }
            
            @Override
            public void modify(Entry<Long, Connection> entry) {
                final Connection con = entry.getValue();
                try {
                    // close the Connection
                    con.close();
                } catch(SQLException se) {
                    LOG.warn("Unable to close JDBC Connection: " + se.getMessage(), se);
                }
            }
        });
        
        // update the context
        //ModuleUtils.storeContextMap(xqueryContext, SQLModule.CONNECTIONS_CONTEXTVAR, connections);